
package com.joysuch.wwyt.datadump.biz.convertor;

import java.util.Collections;
import java.util.List;

import cn.zlg.common.datadump.annotation.DataDumpField;
import cn.zlg.common.datadump.convertor.FieldValueConvert;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import org.springframework.stereotype.Component;

/**
 * 将 [2048,2049]类型的字符串，转换成List<Long>类型
 *
 */
@Component
public class JsonArrayStringToLongListConvertor implements FieldValueConvert<String, List<Long>> {

    @Override
    public List<Long> convert(Object bean, String value, DataDumpField dataField) {
        if (value == null) {
            return Collections.EMPTY_LIST;
        }
        try {
            return new Gson().fromJson(value, new TypeToken<List<Long>>() {
            }.getType());
        } catch (Exception e) {
            return Collections.EMPTY_LIST;
        }
    }

}
